/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using System.Collections.Generic;
using NetProtocol.POD;
using NetProtocol.Enum;
using IQIGame.Onigao.Game;
using IQIGame.Onigao.GamePlay;
using IQIGame.Onigao.Framework;
using System.Threading.Tasks;
using System;

namespace NetProtocol.Server {
	/// <summary>
	/// 装备模块 
	/// module : equip
	/// </summary>
	public interface SNetEquip : INetServerModule {
		Dictionary<int, MessageHandler> INetServerModule.GetModuleFunction()
        {	
            return new()
            {
                { NetMessageId.equip_upLevel, (session, data) =>
		            {
#if ENABLE_NET_LOG || UNITY_EDITOR
						NetProtocolHelper.ServerLog(NetMessageId.equip_upLevel, "Recv->" + data.ToString());
#endif
		                UpLevelRequest _data = (UpLevelRequest)data;
						return CS_upLevel(session, _data.equipId, _data.items);
		            } 
            	},
                { NetMessageId.equip_upStar, (session, data) =>
		            {
#if ENABLE_NET_LOG || UNITY_EDITOR
						NetProtocolHelper.ServerLog(NetMessageId.equip_upStar, "Recv->" + data.ToString());
#endif
		                UpStarRequest _data = (UpStarRequest)data;
						return CS_upStar(session, _data.equipId);
		            } 
            	},
                { NetMessageId.equip_decompose, (session, data) =>
		            {
#if ENABLE_NET_LOG || UNITY_EDITOR
						NetProtocolHelper.ServerLog(NetMessageId.equip_decompose, "Recv->" + data.ToString());
#endif
		                DecomposeRequest _data = (DecomposeRequest)data;
						return CS_decompose(session, _data.equipIds);
		            } 
            	},
                { NetMessageId.equip_reborn, (session, data) =>
		            {
#if ENABLE_NET_LOG || UNITY_EDITOR
						NetProtocolHelper.ServerLog(NetMessageId.equip_reborn, "Recv->" + data.ToString());
#endif
		                RebornRequest _data = (RebornRequest)data;
						return CS_reborn(session, _data.equipId);
		            } 
            	},
                { NetMessageId.equip_lockEquip, (session, data) =>
		            {
#if ENABLE_NET_LOG || UNITY_EDITOR
						NetProtocolHelper.ServerLog(NetMessageId.equip_lockEquip, "Recv->" + data.ToString());
#endif
		                LockEquipRequest _data = (LockEquipRequest)data;
						return CS_lockEquip(session, _data.equipId, _data.isLock);
		            } 
            	},
                { NetMessageId.equip_wearSkin, (session, data) =>
		            {
#if ENABLE_NET_LOG || UNITY_EDITOR
						NetProtocolHelper.ServerLog(NetMessageId.equip_wearSkin, "Recv->" + data.ToString());
#endif
		                WearSkinRequest _data = (WearSkinRequest)data;
						return CS_wearSkin(session, _data.skinCid, _data.equipId);
		            } 
            	},
            };
        }
        
        Dictionary<int, Func<IReceiveMessage>> INetServerModule.GetModuleRequest() 
        {
	        return new ()
	        {
	        	{NetMessageId.equip_upLevel, ()=> new UpLevelRequest()},
	        	{NetMessageId.equip_upStar, ()=> new UpStarRequest()},
	        	{NetMessageId.equip_decompose, ()=> new DecomposeRequest()},
	        	{NetMessageId.equip_reborn, ()=> new RebornRequest()},
	        	{NetMessageId.equip_lockEquip, ()=> new LockEquipRequest()},
	        	{NetMessageId.equip_wearSkin, ()=> new WearSkinRequest()},
	        };
	    }
        
#region Server-side Interface
		/// <summary>
        ///  升级
        /// </summary>
	    protected UpLevelResult CS_upLevel(ISession session, long equipId, Dictionary<int, int> items);
		/// <summary>
        ///  升星
        /// </summary>
	    protected UpStarResult CS_upStar(ISession session, long equipId);
		/// <summary>
        ///  分解
        /// </summary>
	    protected DecomposeResult CS_decompose(ISession session, List<long> equipIds);
		/// <summary>
        ///  重生
        /// </summary>
	    protected RebornResult CS_reborn(ISession session, long equipId);
		/// <summary>
        ///  锁定和解锁...lock是关键字
        /// </summary>
	    protected LockEquipResult CS_lockEquip(ISession session, long equipId, bool isLock);
		/// <summary>
        ///  skinCid为0表示脱下，脱下的时候一定要传id；equipId为0表示批量
        /// </summary>
	    protected WearSkinResult CS_wearSkin(ISession session, int skinCid, long equipId);
#endregion
#region Client-side Interface
		/// <summary>
        ///  物品数据会在Item模块同步
        /// </summary>
        public UpLevelResult SC_upLevelResult(Task<UpLevelResult> future){return new UpLevelResult(future);}
        public UpLevelResult SC_upLevelResult(int code, List<ItemShowPOD> returnItems){return new UpLevelResult(code, returnItems);}
        public UpLevelResult SC_upLevelResult(int code){return new UpLevelResult(code);}
		/// <summary>
        /// 
        /// </summary>
        public UpStarResult SC_upStarResult(Task<UpStarResult> future){return new UpStarResult(future);}
        public UpStarResult SC_upStarResult(int code){return new UpStarResult(code);}
		/// <summary>
        /// 
        /// </summary>
        public DecomposeResult SC_decomposeResult(Task<DecomposeResult> future){return new DecomposeResult(future);}
        public DecomposeResult SC_decomposeResult(int code, List<ItemShowPOD> awardPods){return new DecomposeResult(code, awardPods);}
        public DecomposeResult SC_decomposeResult(int code){return new DecomposeResult(code);}
		/// <summary>
        /// 
        /// </summary>
        public RebornResult SC_rebornResult(Task<RebornResult> future){return new RebornResult(future);}
        public RebornResult SC_rebornResult(int code, List<ItemShowPOD> awardPods){return new RebornResult(code, awardPods);}
        public RebornResult SC_rebornResult(int code){return new RebornResult(code);}
		/// <summary>
        /// 
        /// </summary>
        public LockEquipResult SC_lockEquipResult(Task<LockEquipResult> future){return new LockEquipResult(future);}
        public LockEquipResult SC_lockEquipResult(int code){return new LockEquipResult(code);}
		/// <summary>
        /// 
        /// </summary>
        public WearSkinResult SC_wearSkinResult(Task<WearSkinResult> future){return new WearSkinResult(future);}
        public WearSkinResult SC_wearSkinResult(int code){return new WearSkinResult(code);}
		/// <summary>
        ///  通知解锁了装备皮肤
        /// </summary>
		public bool SC_notifySkinActive(ISession session, int skinCid){
	        return NetProtocolHelper.SendMessage(session, new NotifySkinActive(skinCid));
	    }
	    public void SC_notifySkinActive_Broadcast(List<ISession> sessions, int skinCid){
	        NetProtocolHelper.BroadcastMessage(sessions, new NotifySkinActive(skinCid));
	    }
#endregion

#region Messages
	public class UpLevelResult : MessageResult {
	    private List<ItemShowPOD> returnItems;
	    public UpLevelResult(Task<UpLevelResult> future): base(future) { }
		public UpLevelResult(int code): base(code) { }
		public new UpLevelResult SetDelayCall(Action delayCall) { base.SetDelayCall(delayCall); return this; }
	    internal UpLevelResult(int code, List<ItemShowPOD> returnItems){
	        this.code = code;
	        this.returnItems = returnItems == null ? null : new (returnItems);
	    }
        public override MessageResult GetFutureResult(Task task) { return ((Task<UpLevelResult>)task).Result; }
		public override int GetMessageId() {return NetMessageId.equip_upLevelResult;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.equip_upLevelResult;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(code);
			_out.Write_list_pod(returnItems);
			return si_p;
		}
		public override string ToString() {
    		return "Equip.SC_upLevelResult { "
			+ "code="
			+ code
			+ ", returnItems="
			+ returnItems.ToString<ItemShowPOD>()
			+" }";
		}
	}
	public class UpStarResult : MessageResult {
	    public UpStarResult(Task<UpStarResult> future): base(future) { }
		public UpStarResult(int code): base(code) { }
		public new UpStarResult SetDelayCall(Action delayCall) { base.SetDelayCall(delayCall); return this; }
        public override MessageResult GetFutureResult(Task task) { return ((Task<UpStarResult>)task).Result; }
		public override int GetMessageId() {return NetMessageId.equip_upStarResult;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.equip_upStarResult;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(code);
			return si_p;
		}
		public override string ToString() {
    		return "Equip.SC_upStarResult { "
			+ "code="
			+ code
			+" }";
		}
	}
	public class DecomposeResult : MessageResult {
	    private List<ItemShowPOD> awardPods;
	    public DecomposeResult(Task<DecomposeResult> future): base(future) { }
		public DecomposeResult(int code): base(code) { }
		public new DecomposeResult SetDelayCall(Action delayCall) { base.SetDelayCall(delayCall); return this; }
	    internal DecomposeResult(int code, List<ItemShowPOD> awardPods){
	        this.code = code;
	        this.awardPods = awardPods == null ? null : new (awardPods);
	    }
        public override MessageResult GetFutureResult(Task task) { return ((Task<DecomposeResult>)task).Result; }
		public override int GetMessageId() {return NetMessageId.equip_decomposeResult;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.equip_decomposeResult;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(code);
			_out.Write_list_pod(awardPods);
			return si_p;
		}
		public override string ToString() {
    		return "Equip.SC_decomposeResult { "
			+ "code="
			+ code
			+ ", awardPods="
			+ awardPods.ToString<ItemShowPOD>()
			+" }";
		}
	}
	public class RebornResult : MessageResult {
	    private List<ItemShowPOD> awardPods;
	    public RebornResult(Task<RebornResult> future): base(future) { }
		public RebornResult(int code): base(code) { }
		public new RebornResult SetDelayCall(Action delayCall) { base.SetDelayCall(delayCall); return this; }
	    internal RebornResult(int code, List<ItemShowPOD> awardPods){
	        this.code = code;
	        this.awardPods = awardPods == null ? null : new (awardPods);
	    }
        public override MessageResult GetFutureResult(Task task) { return ((Task<RebornResult>)task).Result; }
		public override int GetMessageId() {return NetMessageId.equip_rebornResult;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.equip_rebornResult;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(code);
			_out.Write_list_pod(awardPods);
			return si_p;
		}
		public override string ToString() {
    		return "Equip.SC_rebornResult { "
			+ "code="
			+ code
			+ ", awardPods="
			+ awardPods.ToString<ItemShowPOD>()
			+" }";
		}
	}
	public class LockEquipResult : MessageResult {
	    public LockEquipResult(Task<LockEquipResult> future): base(future) { }
		public LockEquipResult(int code): base(code) { }
		public new LockEquipResult SetDelayCall(Action delayCall) { base.SetDelayCall(delayCall); return this; }
        public override MessageResult GetFutureResult(Task task) { return ((Task<LockEquipResult>)task).Result; }
		public override int GetMessageId() {return NetMessageId.equip_lockEquipResult;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.equip_lockEquipResult;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(code);
			return si_p;
		}
		public override string ToString() {
    		return "Equip.SC_lockEquipResult { "
			+ "code="
			+ code
			+" }";
		}
	}
	public class WearSkinResult : MessageResult {
	    public WearSkinResult(Task<WearSkinResult> future): base(future) { }
		public WearSkinResult(int code): base(code) { }
		public new WearSkinResult SetDelayCall(Action delayCall) { base.SetDelayCall(delayCall); return this; }
        public override MessageResult GetFutureResult(Task task) { return ((Task<WearSkinResult>)task).Result; }
		public override int GetMessageId() {return NetMessageId.equip_wearSkinResult;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.equip_wearSkinResult;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(code);
			return si_p;
		}
		public override string ToString() {
    		return "Equip.SC_wearSkinResult { "
			+ "code="
			+ code
			+" }";
		}
	}
	public class NotifySkinActive : MessageNotify {
		private int skinCid;
		public NotifySkinActive(int skinCid) {
		    this.skinCid = skinCid;
		}
		public override int GetMessageId() {return NetMessageId.equip_notifySkinActive;}
		public override SendPackage ToPackage() {
			SendPackage si_p = NetProtocolHelper.GetSendPackage();
			si_p.Header.Messagid = NetMessageId.equip_notifySkinActive;
			si_p.StartWrite();
			SOutputStream _out = si_p.OutputStream;
			_out.Write_int(skinCid);
			return si_p;
		}
		public override string ToString() {
			return "Equip.SC_notifySkinActive { "
			+ "skinCid="
			+ skinCid
			+" }";
		}
	}
	private class UpLevelRequest : IReceiveMessage
    {
		internal long equipId;
		internal Dictionary<int, int> items;
        public void FromPackage(ReceivePackage package)
		{
			SInputStream _in = package.InputStream;
            equipId = _in.HasRemaining() ? _in.Read_long() : default;
            items = _in.HasRemaining() ? _in.Read_map_int_int() : default;
		}
        public int GetMessageId() { return NetMessageId.equip_upLevel; }
        public override string ToString()
        {
            return "Equip.upLevel"+ ", equipId="+ equipId+ ", items="+ items.ToString<int, int>();
        }
    }
	private class UpStarRequest : IReceiveMessage
    {
		internal long equipId;
        public void FromPackage(ReceivePackage package)
		{
			SInputStream _in = package.InputStream;
            equipId = _in.HasRemaining() ? _in.Read_long() : default;
		}
        public int GetMessageId() { return NetMessageId.equip_upStar; }
        public override string ToString()
        {
            return "Equip.upStar"+ ", equipId="+ equipId;
        }
    }
	private class DecomposeRequest : IReceiveMessage
    {
		internal List<long> equipIds;
        public void FromPackage(ReceivePackage package)
		{
			SInputStream _in = package.InputStream;
            equipIds = _in.HasRemaining() ? _in.Read_list_long() : default;
		}
        public int GetMessageId() { return NetMessageId.equip_decompose; }
        public override string ToString()
        {
            return "Equip.decompose"+ ", equipIds="+ equipIds.ToString<long>();
        }
    }
	private class RebornRequest : IReceiveMessage
    {
		internal long equipId;
        public void FromPackage(ReceivePackage package)
		{
			SInputStream _in = package.InputStream;
            equipId = _in.HasRemaining() ? _in.Read_long() : default;
		}
        public int GetMessageId() { return NetMessageId.equip_reborn; }
        public override string ToString()
        {
            return "Equip.reborn"+ ", equipId="+ equipId;
        }
    }
	private class LockEquipRequest : IReceiveMessage
    {
		internal long equipId;
		internal bool isLock;
        public void FromPackage(ReceivePackage package)
		{
			SInputStream _in = package.InputStream;
            equipId = _in.HasRemaining() ? _in.Read_long() : default;
            isLock = _in.HasRemaining() ? _in.Read_boolean() : default;
		}
        public int GetMessageId() { return NetMessageId.equip_lockEquip; }
        public override string ToString()
        {
            return "Equip.lockEquip"+ ", equipId="+ equipId+ ", isLock="+ isLock;
        }
    }
	private class WearSkinRequest : IReceiveMessage
    {
		internal int skinCid;
		internal long equipId;
        public void FromPackage(ReceivePackage package)
		{
			SInputStream _in = package.InputStream;
            skinCid = _in.HasRemaining() ? _in.Read_int() : default;
            equipId = _in.HasRemaining() ? _in.Read_long() : default;
		}
        public int GetMessageId() { return NetMessageId.equip_wearSkin; }
        public override string ToString()
        {
            return "Equip.wearSkin"+ ", skinCid="+ skinCid+ ", equipId="+ equipId;
        }
    }
	}
#endregion
}